package cm.day12;


class MyThead2 extends Thread {
    static int sum = 0;

    @Override
    public synchronized void run() {
        while (true) {

                try {
                    if (sum < 100) {

                            Thread.sleep(100);
                            sum++;
                            System.out.println(getName() + sum + "张票");
                        }else {
                        break;

                    }
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }


    }
}


public class Test3 {
    public static void main(String[] args) {
        MyThead2 my1 = new MyThead2();
        MyThead2 my2 = new MyThead2();
        MyThead2 my3 = new MyThead2();
        my1.setName("A");
        my2.setName("B");
        my3.setName("C");
        my1.start();
        my2.start();
        my3.start();
    }
}
